package com.mornd.gulimall.member.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;

/**
 * @author: mornd
 * @dateTime: 2023/8/19 - 7:42
 */

@EnableRedisHttpSession
@Configuration
public class SpringSessionConfig {

    @Bean
    public CookieSerializer cookieSerializer() {
        DefaultCookieSerializer defaultSerializer = new DefaultCookieSerializer();
        defaultSerializer.setDomainName("gulimall.com");
        defaultSerializer.setCookieName("GULI_SESSION");
        return defaultSerializer;
    }

    /**
     * 设置 session 的redis序列化器
     * @Qualifier("springSessionDefaultRedisSerializer") bean的名称需固定
     *
     * @return
     */
    @Bean
    public RedisSerializer<Object> springSessionDefaultRedisSerializer() {
        return new GenericJackson2JsonRedisSerializer();
    }
}
